Ext.namespace("Ext.ux");

Ext.ux.PageSizePlugin = function(config){
    Ext.apply(this, config);
    Ext.ux.PageSizePlugin.superclass.constructor.call(this, {
        store: new Ext.data.SimpleStore({
            fields: ['text', 'value'], 
            data: [['5', 5], ['10', 10], ['15', 15], ['20', 20], ['25', 25], ['30', 30], ['40', 40], ['50', 50], ['100', 100]]
        }),

        mode: 'local',
        editable: false,

        displayField: 'text',
        valueField: 'value',
        allowBlank: false,
        triggerAction: 'all',
        width: 50,
        maskRe: /[0-9]/
    });
};

Ext.extend(Ext.ux.PageSizePlugin, Ext.form.ComboBox, {
    beforeText: '显示',
    afterText: '行/页',
    
    init: function(paging){
        paging.on('render', this.onInitView, this);
    },
    
    onInitView: function(paging){
        paging.add('-', this.beforeText, this, this.afterText);
        
        this.setValue(paging.pageSize);
        
        this.on('select', this.onPageSizeChanged, paging);
        
        this.on('specialkey', function(combo, e){
            if(13 === e.getKey())
            {
                this.onPageSizeChanged.call(paging, this);
            }
        });
    },
    onPageSizeChanged: function(combo){
        this.pageSize = parseInt(combo.getRawValue());
        this.doLoad(0);
    }
});